package com.turing.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.turing.system.entity.Dictionary;
import com.turing.system.entity.Message;
import com.turing.system.service.DictionaryService;
import com.turing.system.mapper.DictionaryMapper;
import enums.ErrorCode;
import org.springframework.stereotype.Service;
import result.Result;

import java.util.*;

/**
 * @author admin
 * @description 针对表【dictionary(字典表)】的数据库操作Service实现
 * @createDate 2023-05-08 14:39:18
 */
@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary>
        implements DictionaryService {


    /**
     * 字典详情
     * @param dicId
     * @param dicName
     * @return
     */
    @Override
    public Result getDic(String dicId, String dicName) {
        LinkedHashMap<String, Object> map = this.baseMapper.getDic(dicId, dicName);
        if (ObjectUtils.isNotEmpty(map)) {
            return Result.success(map);
        }else {
            return Result.fail(ErrorCode.NODATA);
        }
    }

    @Override
    public Result editSave(JSONObject jsonObject) {
        Dictionary dictionary = JSONObject.toJavaObject(jsonObject, Dictionary.class);
        int i = baseMapper.updateById(dictionary);
        if (i > 0) {
            return Result.success();
        } else {
            return Result.fail(ErrorCode.ERROR_EDIT);
        }
    }
}




